<template>
  <a-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="机构" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-select-depart v-decorator="['office']" :trigger-change="true"/>
            </a-form-item>
          </a-col>
          <a-col :span="8">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="年份">
              <a-select v-model="yearDate">
                <a-select-option
                  v-for="item in years"
                  :label="item.label"
                  :value="item.value">
                  {{item.value}}年
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="8">
            <a-form-item label="上传年度报告" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['filePath']" text="年度报告"></j-upload>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
<!--    <div class="drawer-bootom-button" v-show="!disableSubmit">-->
<!--      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">-->
<!--        <a-button style="margin-right: .8rem">返回</a-button>-->
<!--      </a-popconfirm>-->
<!--      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">保存</a-button>-->
<!--    </div>-->
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import {saveReportList,editReportList } from '@/api/api'
  import JDate from '@/components/jeecg/JDate'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import JMultiSelectTag from "@/components/dict/JMultiSelectTag"
  import JUpload from '@/components/jeecg/JUpload'
  export default {
    components: {
      // VueDatepickerLocal,
      JMultiSelectTag,
      JSelectDepart,
      JUpload,
      JDate,
    },
    name: "reportYearsModel",
    data(){
      return{
        yearDate:'',
        serviceProjects:"",
        ser:{},
        years:[],
        form: this.$form.createForm(this),
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelRow: {
          xs: { span: 14 },
          sm: { span: 10 },
        },
        wrapperRow: {
          xs: { span: 14 },
          sm: { span: 14 },
        },
        labelRowCheckbox: {
          xs: { span: 10 },
          sm: { span: 8 },
        },
        wrapperRowCheckbox: {
          xs: { span: 10 },
          sm: { span: 14 },
        },
        dis:false,
        hiding:true,
        drawerWidth:1000,
        confirmLoading: false,
        disableSubmit:false,
        validatorRules:{
        },
        url:{
          fileUpload: window._CONFIG['domianURL']+"/sys/common/upload",
          imgerver: window._CONFIG['domianURL']+"/sys/common/view",
          add:"/jinanCloud/reportManage/add"
        }
      }
    },
    mounted() {
      this.init();
    },
    methods:{
      init(){
        this.getYear();
      },
      getYear(){//获取年
        let date = new Date();
        let current_year = date.getFullYear();
        // this.queryParam.yearDate=current_year;
        this.years=[];
        for (let i = 0; i < 30; i++) {
          let y = current_year - i;
          this.years.push({value:(y),label:(y)+ "年"});
          // this.yearDate.push(y);
          if(y=='1970'){
            return
          }
        }
      },
      close () {
        this.$emit('close');
        this.visible = false;
        this.disableSubmit = false;
      },
      add () {
        this.edit({});
      },
      edit(record){
        if(record.yearDate==null){
          this.yearDate='';
        } else {
          this.yearDate = record.yearDate+'年' ;
        }
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'years','type','office','filePath' ))
        });
      },
      handleCancel () {
        this.close()
      },
      handleSubmit () {
        debugger
        let self = this ;
        let year = this.yearDate.toString();
        if(year.indexOf("年") != -1 ){
          year= year.substring(0,4)
        }
        let years={years:year};
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;

            let formData = Object.assign(this.model, values,years);
            let obj;
            formData.type="3"
            if(!this.model.id){
              obj=saveReportList(formData);
            }else{
              obj=editReportList(formData);
            }
            obj.then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;

              that.close();
            })

          }
        })
      },
    },
  }
</script>

<style scoped>

</style>